﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Payroll;

namespace pay_mng
{
    public partial class PayForm : Form
    {
        private PayrollDatabase payrollDatabase = MySqlPayrollDatabase.Instance;
        public PayForm()
        {
            InitializeComponent();
        }

        private void payBtn_Click(object sender, EventArgs e)
        {
            DateTime payDate = this.dateTimePicker1.Value;
            PaydayTransaction paydayTx = new PaydayTransaction(payDate, this.payrollDatabase);
            paydayTx.Execute();
            IList list = payrollDatabase.GetAllEmployees();
            int cnt = 0;
            foreach (Employee employee in list)
            {
                Paycheck paycheck = paydayTx.GetPaycheck(employee.EmpId);
                if (paycheck != null && paycheck.NetPay > 0)
                {
                    cnt++;
                    MessageBox.Show("支付给 [" + employee.EmpId + "]"+employee.Name+"  净工资 $" + paycheck.NetPay,
                        "通知");
                }
            }

            MessageBox.Show("共付 " + cnt + " 人薪水", "通知");
            this.Close();
        }
    }
}
